<?php
/**
 * Dayscript
 * 
 * @category	Loader
 * @package		dayscript.loader.adapter
 * @subpackage	
 * @author		Nelson Daza <ndaza@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license		
 * @version		1.0
 * @version		$Revision: 0 $
 * @filesource	
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		
 * @since		1.0
 * @modifiedby	$LastChangedBy: Nelson Daza $
 * @modified	$Date: 2009-08-13 $
 */

namespace dayscript\loader\adapter;

/**
 * Dayscript
 * 
 * Library auto loader for Dayscript framework.
 * 
 * @category	Loader
 * @package		dayscript.loader.adapter
 * @subpackage	
 * @author		Nelson Daza <ndaza@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license		
 * @version		1.0
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		\dayscript\loader\Loader
 * @since		1.0
 * @modifiedby	$LastChangedBy: Nelson Daza $
 * @modified	$Date: 2009-09-01 $
 */
class Dayscript extends \dayscript\loader\Loader	{
	/**
	 * Dayscript constructor
	 * @param string $name Loader identifier
	 * @return Dayscript
	 */
	public function __construct( $name )	{
		parent::__construct( $name, \dirname( \dirname( \dirname( __DIR__ ) ) ) . \DIRECTORY_SEPARATOR, '.class.php' );
	}
	/**
	 * {@inheritdoc }
	 */
	public function canLoadClass( $className )	{
		return ( \strpos( $className, 'dayscript\\' ) === 0  && \file_exists( $this->libraryDir . \str_replace( '\\', \DIRECTORY_SEPARATOR, $className ) . $this->extension ) );
	}
	/**
	 * {@inheritdoc }
	 */
	public function loadClass( $className )	{
		$path = $this->libraryDir . \str_replace( '\\', \DIRECTORY_SEPARATOR, $className ) . $this->extension;		
		if( \strpos( $className, 'dayscript\\' ) === 0 &&  \file_exists( $path ) )
			require( $path );			
	}
}